package web;

import api.BenchmarkFactory;
import api.BenchmarkModule;
import api.Configuration;
import api.result.Result;
import org.springframework.boot.SpringApplication;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@CrossOrigin(origins = "*")
@RestController
public class BenchmarkController {
    @RequestMapping(path = "/startBench", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public String startBench(@RequestBody Configuration configuration) {
        BenchmarkModule benchmark = null;
        try {
            benchmark = new BenchmarkFactory().createBenchmark(configuration);

        } catch (BenchmarkFactory.UndefinedConfigException e) {
            throw new RuntimeException(e);
        }
        Result r1 = benchmark.loadData();
        Result r2 = benchmark.runBenchmark();
        return r2.union(r1).toString();
    }
}
